package com.parachutes.aspbillcore.controller;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.domain.AlipayFundTransUniTransferModel;
import com.alipay.api.domain.Participant;

import com.alipay.api.FileItem;
import java.util.Base64;
import java.util.ArrayList;
import java.util.List;

public class AlipayFundTransUniTransfer {

    public static void main(String[] args) throws AlipayApiException {
        // 初始化SDK
        AlipayClient alipayClient = new DefaultAlipayClient(getAlipayConfig());

        // 构造请求参数以调用接口
        AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
        AlipayFundTransUniTransferModel model = new AlipayFundTransUniTransferModel();

        // 设置商家侧唯一订单号
        model.setOutBizNo("20180630005");

        // 设置订单总金额
        model.setTransAmount("23.00");

        // 设置描述特定的业务场景
        model.setBizScene("DIRECT_TRANSFER");

        // 设置业务产品码
        model.setProductCode("TRANS_ACCOUNT_NO_PWD");

        // 设置转账业务的标题
        model.setOrderTitle("API分享平台收益提现");

        // 设置收款方信息
        Participant payeeInfo = new Participant();
        payeeInfo.setIdentity("ucfvsd2479@sandbox.com");
        payeeInfo.setName("ucfvsd2479");
        payeeInfo.setIdentityType("ALIPAY_LOGON_ID");
        model.setPayeeInfo(payeeInfo);

        // 设置业务备注
        model.setRemark("广州深圳降落伞科技有限公司-代发");

        // 设置转账业务请求的扩展参数
//        model.setBusinessParams("{\"payer_show_name_use_alias\":\"true\"}");

        request.setBizModel(model);
        AlipayFundTransUniTransferResponse response = alipayClient.certificateExecute(request);
        System.out.println(response.getBody());

        if (response.isSuccess()) {
            System.out.println("调用成功");
        } else {
            System.out.println("调用失败");
            // sdk版本是"4.38.0.ALL"及以上,可以参考下面的示例获取诊断链接
            // String diagnosisUrl = DiagnosisUtils.getDiagnosisUrl(response);
            // System.out.println(diagnosisUrl);
        }
    }

    private static Alip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l3E6V6/BByf2Bg75a20YfYjcxD6toO2+TP25n34iXChaBlkYwKBgAhrhlm+DWMR/ziWex7+T4h4nnqDYCpo0Uh+2EuCZ1taHtFlSz3CwGToUYtkMB9texNm5baszvbm6sils9qM5oNSRSS6e33gG3QSGML+EHOmMQLtJt7FOK2ebRkgiIRyTP+sT430OODUJ5UDb5HskNodmJP2drjwgi476P0vx3T/AoGAGn/93ejMcA3xxUQYrmekwPzK+2wXSSfeA+Jx++3N7lC6TJ9DEK3JOchMfS4PdSjJvOCFA7kgXWw1tDu6jdn1jcNmWa3hbJnZWSTIs7Zj79BbadW4+qYYYGlyGM+nt8O8/uQO4PKSlTF0FSWEx0Q6FvAxIRSJ39jPFTc6q1PlOz0CgYA++SQcJxeTKHDlv4092G8ovrey9vOesbI7GmhyZ1MhqpnGkh3CA5LkPDnXlp4K9TiOggGxDSMtio5vibIrq2vN/kQsSiSamafbU3GUBFG3GpCGevlPbzwoNmBTNRds4+BVZkUTE3i3idHnhiZCMnu1E+l8DDFMcyLh0dvOKQTVyw==";
        AlipayConfig alipayConfig = new AlipayConfig();
        alipayConfig.setPrivateKey(privateKey);
        alipayConfig.setServerUrl("https://openapi-sandbox.dl.alipaydev.com/gateway.do");
        alipayConfig.setAppId("9021000143641216");
        alipayConfig.setCharset("UTF-8");
        alipayConfig.setSignType("RSA2");
        alipayConfig.setFormat("json");
        alipayConfig.setAppCertPath("D:\\code\\java\\API-Sharing-Platform\\asp-bill\\asp-bill-core\\src\\main\\resources\\appPublicCert.crt");
        alipayConfig.setAlipayPublicCertPath("D:\\code\\java\\API-Sharing-Platform\\asp-bill\\asp-bill-core\\src\\main\\resources\\alipayPublicCert.crt");
        alipayConfig.setRootCertPath("D:\\code\\java\\API-Sharing-Platform\\asp-bill\\asp-bill-core\\src\\main\\resources\\alipayRootCert.crt");
        return alipayConfig;
    }
}